package com.framework.modules.base.controller;

import java.util.Arrays;
import java.util.Map;

import com.framework.common.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.framework.modules.base.entity.UserInfoEntity;
import com.framework.modules.base.service.UserInfoService;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 用户信息表
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-21 01:30:14
 */
@RestController
@RequestMapping("base/userinfo")
@Api(tags = "UserInfoController")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
        @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{uid}")
        @ApiOperation("info")
    public R info(@PathVariable("uid") Integer uid){
        UserInfoEntity userInfo = userInfoService.selectById(uid);

        return R.ok().put("userInfo", userInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        @ApiOperation("save")
    public R save(@RequestBody UserInfoEntity userInfo){
        userInfoService.insert(userInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        @ApiOperation("update")
    public R update(@RequestBody UserInfoEntity userInfo){
        ValidatorUtils.validateEntity(userInfo);
        userInfoService.updateAllColumnById(userInfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        @ApiOperation("delete")
    public R delete(@RequestBody Integer[] uids){
        userInfoService.deleteBatchIds(Arrays.asList(uids));

        return R.ok();
    }

}
